package com.didibigdata.servlets;

import com.didibigdata.Repositories.OrderTimeRepository;
import com.didibigdata.entities.OrderTime;
import com.didibigdata.entities.OrderTimeType;
import com.fasterxml.jackson.databind.ObjectMapper;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

@WebServlet("/OrderTimeServlet")
public class OrderTimeServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        OrderTimeRepository orderTimeRepository = new OrderTimeRepository();
        List<OrderTimeType> orderTimeTypeList = orderTimeRepository.getOrderTimeTypeList();
        ObjectMapper mapper = new ObjectMapper();
        String json = mapper.writeValueAsString(orderTimeTypeList);
        response.setContentType("text/html; charset=utf-8");
        response.getWriter().write(json);
    }
}
